<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:common:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:common:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:common:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:common:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="commonList" @selection-change="handleSelectionChange">
      <el-table-column label="标题" align="center" prop="title"/>
      <el-table-column label="内容" align="center" prop="contents"/>
      <el-table-column label="描述" align="center" prop="describe"/>
      <el-table-column label="考核部门id" align="center" prop="examineDeptId"/>
      <el-table-column label="培训时间" align="center" prop="trainingTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.trainingTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="截止时间" align="center" prop="endTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="考核周期" align="center" prop="examineCycle"/>
      <el-table-column label="考核年度" align="center" prop="examineYear"/>
      <el-table-column label="附件" align="center" prop="attachFile"/>
      <el-table-column label="发布人id" align="center" prop="pubUserId"/>
      <el-table-column label="发布时间" align="center" prop="pubTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.pubTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核人id" align="center" prop="apprUserId"/>
      <el-table-column label="审核时间" align="center" prop="apprTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.apprTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="任务状态" align="center" prop="missionStatus"/>
      <el-table-column label="考核人员id" align="center" prop="examineUserId"/>
      <el-table-column label="考核时间" align="center" prop="examineTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.examineTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="考核类型" align="center" prop="examineType"/>
      <el-table-column label="优秀积分" align="center" prop="excellentScore"/>
      <el-table-column label="优秀荣誉值" align="center" prop="excellentHonorScore"/>
      <el-table-column label="优秀人数占比" align="center" prop="excellentPersonScale"/>
      <el-table-column label="良好积分" align="center" prop="goodScore"/>
      <el-table-column label="良好荣誉值" align="center" prop="goodHonorScore"/>
      <el-table-column label="良好人数占比" align="center" prop="goodPersonScale"/>
      <el-table-column label="称职积分" align="center" prop="qualifiedScore"/>
      <el-table-column label="称职荣誉值" align="center" prop="qualifiedHonorScore"/>
      <el-table-column label="称职人数占比" align="center" prop="qualifiedPersonScale"/>
      <el-table-column label="基本称职积分" align="center" prop="almostScore"/>
      <el-table-column label="基本称职荣誉值" align="center" prop="almostHonorScore"/>
      <el-table-column label="基本称职人数占比" align="center" prop="almostPersonScale"/>
      <el-table-column label="不称职积分" align="center" prop="unqualifiedScore"/>
      <el-table-column label="不称职荣誉值" align="center" prop="unqualifiedHonorScore"/>
      <el-table-column label="不称职人数占比" align="center" prop="unqualifiedPersonScale"/>
      <el-table-column label="优秀人数" align="center" prop="excellentCount"/>
      <el-table-column label="良好人数" align="center" prop="goodCount"/>
      <el-table-column label="称职人数" align="center" prop="qualifiedCount"/>
      <el-table-column label="基本称职人数" align="center" prop="almostCount"/>
      <el-table-column label="不称职人数" align="center" prop="unqualifiedCount"/>
      <el-table-column label="审核状态" align="center" prop="approveStatus"/>
      <el-table-column label="考评状态" align="center" prop="examineStatus"/>
      <el-table-column label="荣誉值" align="center" prop="honorScore"/>
      <el-table-column label="当前审批人id" align="center" prop="currentApprId"/>
      <el-table-column label="审批意见" align="center" prop="apprOppinion"/>
      <el-table-column label="培训地点" align="center" prop="trainingLocation"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:common:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:common:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改通用考核对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="标题" prop="title">
          <el-input v-model="form.title" placeholder="请输入标题"/>
        </el-form-item>
        <el-form-item label="内容" prop="contents">
          <el-input v-model="form.contents" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="描述" prop="describe">
          <el-input v-model="form.describe" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="考核部门id" prop="examineDeptId">
          <el-input v-model="form.examineDeptId" placeholder="请输入考核部门id"/>
        </el-form-item>
        <el-form-item label="培训时间" prop="trainingTime">
          <el-date-picker clearable
                          v-model="form.trainingTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择培训时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="截止时间" prop="endTime">
          <el-date-picker clearable
                          v-model="form.endTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择截止时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="考核周期" prop="examineCycle">
          <el-input v-model="form.examineCycle" placeholder="请输入考核周期"/>
        </el-form-item>
        <el-form-item label="考核年度" prop="examineYear">
          <el-input v-model="form.examineYear" placeholder="请输入考核年度"/>
        </el-form-item>
        <el-form-item label="附件">
          <file-upload v-model="form.attachFile"/>
        </el-form-item>
        <el-form-item label="发布人id" prop="pubUserId">
          <el-input v-model="form.pubUserId" placeholder="请输入发布人id"/>
        </el-form-item>
        <el-form-item label="发布时间" prop="pubTime">
          <el-date-picker clearable
                          v-model="form.pubTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择发布时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审核人id" prop="apprUserId">
          <el-input v-model="form.apprUserId" placeholder="请输入审核人id"/>
        </el-form-item>
        <el-form-item label="审核时间" prop="apprTime">
          <el-date-picker clearable
                          v-model="form.apprTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择审核时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="考核人员id" prop="examineUserId">
          <el-input v-model="form.examineUserId" placeholder="请输入考核人员id"/>
        </el-form-item>
        <el-form-item label="考核时间" prop="examineTime">
          <el-date-picker clearable
                          v-model="form.examineTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择考核时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="优秀积分" prop="excellentScore">
          <el-input v-model="form.excellentScore" placeholder="请输入优秀积分"/>
        </el-form-item>
        <el-form-item label="优秀荣誉值" prop="excellentHonorScore">
          <el-input v-model="form.excellentHonorScore" placeholder="请输入优秀荣誉值"/>
        </el-form-item>
        <el-form-item label="优秀人数占比" prop="excellentPersonScale">
          <el-input v-model="form.excellentPersonScale" placeholder="请输入优秀人数占比"/>
        </el-form-item>
        <el-form-item label="良好积分" prop="goodScore">
          <el-input v-model="form.goodScore" placeholder="请输入良好积分"/>
        </el-form-item>
        <el-form-item label="良好荣誉值" prop="goodHonorScore">
          <el-input v-model="form.goodHonorScore" placeholder="请输入良好荣誉值"/>
        </el-form-item>
        <el-form-item label="良好人数占比" prop="goodPersonScale">
          <el-input v-model="form.goodPersonScale" placeholder="请输入良好人数占比"/>
        </el-form-item>
        <el-form-item label="称职积分" prop="qualifiedScore">
          <el-input v-model="form.qualifiedScore" placeholder="请输入称职积分"/>
        </el-form-item>
        <el-form-item label="称职荣誉值" prop="qualifiedHonorScore">
          <el-input v-model="form.qualifiedHonorScore" placeholder="请输入称职荣誉值"/>
        </el-form-item>
        <el-form-item label="称职人数占比" prop="qualifiedPersonScale">
          <el-input v-model="form.qualifiedPersonScale" placeholder="请输入称职人数占比"/>
        </el-form-item>
        <el-form-item label="基本称职积分" prop="almostScore">
          <el-input v-model="form.almostScore" placeholder="请输入基本称职积分"/>
        </el-form-item>
        <el-form-item label="基本称职荣誉值" prop="almostHonorScore">
          <el-input v-model="form.almostHonorScore" placeholder="请输入基本称职荣誉值"/>
        </el-form-item>
        <el-form-item label="基本称职人数占比" prop="almostPersonScale">
          <el-input v-model="form.almostPersonScale" placeholder="请输入基本称职人数占比"/>
        </el-form-item>
        <el-form-item label="不称职积分" prop="unqualifiedScore">
          <el-input v-model="form.unqualifiedScore" placeholder="请输入不称职积分"/>
        </el-form-item>
        <el-form-item label="不称职荣誉值" prop="unqualifiedHonorScore">
          <el-input v-model="form.unqualifiedHonorScore" placeholder="请输入不称职荣誉值"/>
        </el-form-item>
        <el-form-item label="不称职人数占比" prop="unqualifiedPersonScale">
          <el-input v-model="form.unqualifiedPersonScale" placeholder="请输入不称职人数占比"/>
        </el-form-item>
        <el-form-item label="优秀人数" prop="excellentCount">
          <el-input v-model="form.excellentCount" placeholder="请输入优秀人数"/>
        </el-form-item>
        <el-form-item label="良好人数" prop="goodCount">
          <el-input v-model="form.goodCount" placeholder="请输入良好人数"/>
        </el-form-item>
        <el-form-item label="称职人数" prop="qualifiedCount">
          <el-input v-model="form.qualifiedCount" placeholder="请输入称职人数"/>
        </el-form-item>
        <el-form-item label="基本称职人数" prop="almostCount">
          <el-input v-model="form.almostCount" placeholder="请输入基本称职人数"/>
        </el-form-item>
        <el-form-item label="不称职人数" prop="unqualifiedCount">
          <el-input v-model="form.unqualifiedCount" placeholder="请输入不称职人数"/>
        </el-form-item>
        <el-form-item label="荣誉值" prop="honorScore">
          <el-input v-model="form.honorScore" placeholder="请输入荣誉值"/>
        </el-form-item>
        <el-form-item label="当前审批人id" prop="currentApprId">
          <el-input v-model="form.currentApprId" placeholder="请输入当前审批人id"/>
        </el-form-item>
        <el-form-item label="审批意见" prop="apprOppinion">
          <el-input v-model="form.apprOppinion" placeholder="请输入审批意见"/>
        </el-form-item>
        <el-form-item label="培训地点" prop="trainingLocation">
          <el-input v-model="form.trainingLocation" placeholder="请输入培训地点"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listCommon, getCommon, delCommon, addCommon, updateCommon} from "@/api/examine/api";

export default {
  name: "Common",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 通用考核表格数据
      commonList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: null,
        contents: null,
        describe: null,
        examineDeptId: null,
        trainingTime: null,
        endTime: null,
        examineCycle: null,
        examineYear: null,
        attachFile: null,
        pubUserId: null,
        pubTime: null,
        apprUserId: null,
        apprTime: null,
        missionStatus: null,
        examineUserId: null,
        examineTime: null,
        examineType: null,
        excellentScore: null,
        excellentHonorScore: null,
        excellentPersonScale: null,
        goodScore: null,
        goodHonorScore: null,
        goodPersonScale: null,
        almostScore: null,
        almostHonorScore: null,
        almostPersonScale: null,
        qualifiedScore: null,
        qualifiedHonorScore: null,
        qualifiedPersonScale: null,
        unqualifiedScore: null,
        unqualifiedHonorScore: null,
        unqualifiedPersonScale: null,
        excellentCount: null,
        goodCount: null,
        almostCount: null,
        qualifiedCount: null,
        unqualifiedCount: null,
        approveStatus: null,
        examineStatus: null,
        honorScore: null,
        currentApprId: null,
        apprOppinion: null,
        trainingLocation: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询通用考核列表 */
    getList() {
      this.loading = true;
      listCommon(this.queryParams).then(response => {
        this.commonList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        title: null,
        contents: null,
        describe: null,
        examineDeptId: null,
        trainingTime: null,
        endTime: null,
        examineCycle: null,
        examineYear: null,
        attachFile: null,
        pubUserId: null,
        pubTime: null,
        apprUserId: null,
        apprTime: null,
        missionStatus: 0,
        examineUserId: null,
        examineTime: null,
        examineType: null,
        excellentScore: null,
        excellentHonorScore: null,
        excellentPersonScale: null,
        almostScore: null,
        almostHonorScore: null,
        almostPersonScale: null,
        goodScore: null,
        goodHonorScore: null,
        goodPersonScale: null,
        qualifiedScore: null,
        qualifiedHonorScore: null,
        qualifiedPersonScale: null,
        unqualifiedScore: null,
        unqualifiedHonorScore: null,
        unqualifiedPersonScale: null,
        excellentCount: null,
        almostCount: null,
        goodCount: null,
        qualifiedCount: null,
        unqualifiedCount: null,
        approveStatus: 0,
        examineStatus: 0,
        honorScore: null,
        currentApprId: null,
        apprOppinion: null,
        trainingLocation: null,
        updateTime: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加通用考核";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCommon(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改通用考核";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCommon(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCommon(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除通用考核编号为"' + ids + '"的数据项？').then(function () {
        return delCommon(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/common/export', {
        ...this.queryParams
      }, `common_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
